/*
* SinkholeController.java
* Created on  2015/7/27 15:14
* 版本       修改时间          作者      修改内容
* V1.0.1    2015/7/27       longshihui    初始版本
*
*/

package com.infitecs.eyas.tools;

import com.infitecs.eyas.expression.service.ToolExpressionService;
import com.infitecs.eyas.session.SessionService;
import com.infitecs.eyas.tool.Sinkhole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 类的描述信息
 *
 * @author longshihui
 * @version 1.0.1
 */
@Controller
@RequestMapping("/tools/sinkhole")
public class SinkholeController {

    @Autowired
    private ToolExpressionService toolExpressionService;

    @Autowired
    private SessionService sessionService;

    @RequestMapping("")
    public String getPage(){
        sessionService.setEnvironment('T');
        return "tools/sinkhole";
    }

    @RequestMapping(value = "/updateParam",method = RequestMethod.POST)
    @ResponseBody
    public void updateParam(Sinkhole sinkhole) {
        toolExpressionService.updateToolsParam(sinkhole);
    }

    @RequestMapping(value = "/clean",method = RequestMethod.POST)
    @ResponseBody
    public void clean() {
        toolExpressionService.clearMap();
        toolExpressionService.clearResultMap();
    }

    @RequestMapping(value = "/calE15",method = RequestMethod.GET)
    @ResponseBody
    public Double calE15() {
        return toolExpressionService.calculate("TE15");
    }

    @RequestMapping(value = "/cal", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Double> calAll() {
        Map<String,Double> map = new HashMap<>();
        toolExpressionService.calculate("TE14");
        map.put("e19", toolExpressionService.calculate("TE19"));
        map.put("e21",toolExpressionService.calculate("TE21"));
        map.put("e216",toolExpressionService.calculate("TE216"));
        map.put("e217",toolExpressionService.calculate("TE217"));
        toolExpressionService.getResult().put("p", map.get("e19"));
        toolExpressionService.getResult().put("z",map.get("e210"));
        toolExpressionService.getResult().put("lost",map.get("e216") * map.get("e19"));
        return map;
    }
}
